<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link type="text/css" rel="stylesheet" href="public/css/style1.css" />
<?php
require_once 'model/db.php';


?>

<h1>Trung Duc</h1>
<?php 
    $query = "SELECT * FROM companies";
    $companies = getData($query);
?>
<form method="POST">
    Min fans<input type="text" name="min_fans"><br>
    Max fans<input type="text" name="max_fans"><br>
    Keyword <input type="text" name="keyword"><br>
    Company<select name="id_company">
        <?php foreach ($companies as $company): ?>
        <option value="<?php echo $company['id'] ?>"><?php echo $company['name']?></option>
        <?php        endforeach;?>
    </select>
    <input type="submit" name="submit" value="OK">
</form>

<?php if (isset($_POST['submit'])):?>
    <?php 
     
        $min_fans = $_POST['min_fans'];//TODO
        $max_fans = $_POST['max_fans'];//TODO
        $keyword = $_POST['keyword'];//TODO
        $copanies = $_POST['id_company'];//TODO
        //$app = $_POST['id_app'];//TODO
        
        
        $query = "SELECT * FROM pages 
                
                  
                  WHERE (likes <= $max_fans)
                      AND (likes >= $min_fans)
                      AND (description LIKE '% $keyword %')
                  LIMIT 0, 10
                  ";
        
        //var_dump($query);
        $pages = getData($query);
    ?>

    <?php if (!empty($pages)):?>
<div class="bang">
    <table border="1">
        
        <tr class="bang1">
        
            <td> Profile </td>
            <td> Likes </td>
            <td> Name </td>
            <td> About</td>
            <td> Description </td>
        
            
            
            
        </tr>
         
        <?php foreach ($pages as $page):?>
            <tr>
                <td><img src="<?php echo $page['picture']?>"></td>
                <td><?php echo $page['likes'] ?></td>
                <td><?php echo $page['name'] ?></td>
                <td><?php echo $page['about'] ?></td>
                <td><?php echo substr($page['description'],0, 100) ?>....</td>
                
                
                
            </tr>
        <?php endforeach; ?>
    </table> 
    </div>

    <?php endif;?>
<?php endif;?>
